#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use std::process::Command;

use icon_utils::{get_file_icon, hicon_to_base64};

mod icon_utils;

// 调用cmd执行文件
#[tauri::command]
fn open_application(path: &str) -> String {
    Command::new("cmd")
        .args(&["/C", "start", "", &path])
        .spawn()
        .unwrap();
    "操作成功".to_string()
}

// 获取文件icon
#[tauri::command]
fn get_icon_base64(path: String) -> String {
    let hicon = get_file_icon(&path).unwrap();
    hicon_to_base64(hicon).unwrap()
}

fn main() {
    tauri::Builder::default()
        .invoke_handler(tauri::generate_handler![open_application, get_icon_base64])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}
